home *** CD-ROM | disk | FTP | other *** search
- /* This example use of exif.library reads and displays any exif
- thumbnail (in RGB format).
- */
-
- #include <stdio.h>
-
- #include <exec/memory.h>
- #include <exec/types.h>
-
- #include <clib/exec_protos.h>
- #include <clib/cybergraphics_protos.h>
- #include <clib/intuition_protos.h>
-
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/intuition_pragmas.h>
- #include <pragmas/cybergraphics_pragmas.h>
-
- #include <guigfx/guigfx.h>
- #include <pragmas/guigfx_pragmas.h>
- #include <guigfx/guigfx_protos.h>
-
- #include <jpeg/jpeg.h>
- #include <jpeg/jpeg_protos.h>
- #include <jpeg/jpeg_pragmas.h>
-
- #include <exif/exif.h>
- #include <exif/exif_protos.h>
- #include <exif/exif_pragmas.h>
-
- /* Function prototypes */
- void DisplayGuiGfx( UBYTE *buffer, UBYTE cs, ULONG rs, ULONG x, ULONG y );
-
- struct Library *ExifBase, *JpegBase;
-
- char *version = "$VER: showthumbnail 1.0 (3.1.2001)";
-
- void main( int argc, char **argv )
- {
- if ( argv[1] )
- {
- ExifBase = OpenLibrary( "exif.library", 1 );
- JpegBase = OpenLibrary( "jpeg.library", 6 );
-
- if ( ExifBase && JpegBase )
- {
- struct Exif *exif;
-
- exif = ReadExif( argv[1], NULL );
- if ( exif )
- {
- ULONG err;
- struct JPEGDecHandle *jph;
- UBYTE *buffer;
- ULONG x, y, rs;
- UBYTE colourspace;
- ULONG bpp;
-
- printf( "Exif length=%ld\n", exif->ExifLength );
-
- if ( exif->ThumbnailData )
- {
- printf( "Thumbnail size=%ld\n", exif->ThumbnailSize );
-
- err = AllocJPEGDecompress( &jph,
- JPG_SrcMemStream, exif->ThumbnailData,
- JPG_SrcMemStreamSize, exif->ThumbnailSize,
- TAG_DONE );
- if ( !err )
- {
- err = GetJPEGInfo( jph,
- JPG_Width, &x, JPG_Height, &y,
- JPG_ColourSpace, &colourspace,
- JPG_BytesPerPixel, &bpp,
- JPG_RowSize, &rs,
- TAG_DONE );
- if ( !err )
- {
- buffer = AllocBufferFromJPEG( jph, TAG_DONE );
- if ( buffer != NULL )
- {
- err = DecompressJPEG( jph,
- JPG_DestRGBBuffer, buffer,
- TAG_DONE );
- if ( !err )
- {
- DisplayGuiGfx( buffer, colourspace, rs, x, y );
- }
- else printf( "decompress jpeg error:%d\n", err );
-
- FreeJPEGBuffer( buffer );
- }
- else printf( "cant allocate rgb buffer\n" );
- }
- else printf( "get jpeg info error:%d\n", err );
-
- FreeJPEGDecompress( jph );
- }
- else printf("cant allocate jpeg decompress = %ld\n",err);
- }
- else printf( "thumbnail not in jpeg format (or no thumbnail)\n" );
-
- FreeExif( exif );
- }
- }
-
- if ( ExifBase != NULL ) CloseLibrary( ExifBase );
- else printf( "you need exif.library v1.0 minimum\n" );
-
- if ( JpegBase != NULL ) CloseLibrary( JpegBase );
- else printf( "you need jpeg.library v6.0 minimum\n" );
- }
- else
- {
- printf( "no source file specified\n" );
- }
- }
-
- void DisplayGuiGfx( UBYTE *buffer, UBYTE cs, ULONG rs, ULONG x, ULONG y )
- {
- struct Library *GuiGFXBase, *IntuitionBase;
-
- IntuitionBase = OpenLibrary( "intuition.library", 39 );
- GuiGFXBase = OpenLibrary( "guigfx.library", 17 );
- if ( GuiGFXBase && IntuitionBase )
- {
- struct Window *win;
- APTR dh, pi;
- UBYTE *argb;
-
- win = OpenWindowTags( NULL,
- WA_Title, "Proof",
- WA_Flags, WFLG_ACTIVATE | WFLG_SIMPLE_REFRESH |
- WFLG_SIZEGADGET | WFLG_RMBTRAP | WFLG_DRAGBAR |
- WFLG_DEPTHGADGET | WFLG_CLOSEGADGET,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
- IDCMP_SIZEVERIFY | IDCMP_NEWSIZE | IDCMP_RAWKEY,
- WA_Left, 16,
- WA_Top, 16,
- WA_Width, x,
- WA_Height, y,
- TAG_DONE );
-
- if ( win != NULL )
- {
- dh = ObtainDrawHandle( NULL, win->RPort, win->WScreen->ViewPort.ColorMap, TAG_DONE );
-
- if ( dh )
- {
- argb = AllocVec( x * y * 4, MEMF_PUBLIC | MEMF_CLEAR );
-
- if ( argb )
- {
- int i, count = 0;
- char **dest;
-
- /* Convert an RGB buffer to an ARGB buffer setting A to 0.*/
- dest = (char **)argb;
-
- for ( i = 0; i < x * y * 3; i += 3 )
- {
- dest[count++] = (char *)( ( (ULONG) * (char**)&buffer[i] ) >> 8 );
- }
-
- pi = MakePicture( argb, x, y, GGFX_PixelFormat, PIXFMT_0RGB_32, TAG_DONE );
-
- if ( pi )
- {
- struct Message *msg;
-
- DrawPicture( dh, pi, 0, 0, NULL );
-
- Wait( 1L << win->UserPort->mp_SigBit );
-
- while ( ( msg = GetMsg( win->UserPort ) ) != NULL ) ReplyMsg( msg );
-
- DeletePicture( pi );
- }
- else printf( "failed to create picture\n" );
-
- FreeVec( argb );
- }
- else printf( "failed to allocate argb buffer\n" );
-
- ReleaseDrawHandle( dh );
- }
- else printf( "failed to get drawhandle\n" );
-
- CloseWindow( win );
- }
- else printf( "failed to open window\n" );
- }
- else printf( "failed to open guigfx.library\n" );
-
- if ( IntuitionBase ) CloseLibrary( IntuitionBase );
-
- if ( GuiGFXBase ) CloseLibrary( GuiGFXBase );
- else printf( "you need guigfx.library v17.0 minimum\n" );
- }
-